package com.mgs.product.tagger.handlers
{
	import com.mgs.fwk.test.AssertUtil;
	import com.mgs.product.tagger.actions.AccessCellAction;
	import com.mgs.product.tagger.model.Axis;
	import com.mgs.product.tagger.model.Classifiable;
	import com.mgs.product.tagger.model.Classification;
	import com.mgs.product.tagger.model.Document;
	import com.mgs.product.tagger.model.Segment;
	import com.mgs.product.tagger.ui.dto.NavigationContext;
	
	import flexunit.framework.Assert;
	
	import mx.collections.ArrayList;

	public class AccessCellHandlerTestCase
	{
		private var context:NavigationContext;
		
		private var handler:AccessCellHandler;
		
		private var action:AccessCellAction;
		
		[Before]
		public function setUp():void
		{
			handler = new AccessCellHandler();
		}
		
		[Test]
		public function testNominal():void
		{
			// setup context
			context = new NavigationContext();
			context.classification = new Classification();
			context.classification.elements = new Vector.<Classifiable>();
			context.activeTags = new Vector.<Segment>();
			
			var segA:Segment = new Segment();
			var segB:Segment = new Segment();
			
			var element:Document = new Document();
			element.tags = new Vector.<Segment>();
			element.tags.push(segA, segB);
			
			// setup action
			action = new AccessCellAction();
			action.tags = new Vector.<Segment>();
			action.tags.push(segB, segA);
			
			// execute action
			handler.execute(context, action);
			
			// assertions
			AssertUtil.assertEquals(context.activeTags, element.tags);
			Assert.assertTrue(context.invalidActiveTags);
		}
		
		[Test]
		public function testGotoRoot():void
		{
			// setup context
			context = new NavigationContext();
			context.classification = new Classification();
			context.classification.elements = new Vector.<Classifiable>();
			
			var segA:Segment = new Segment();
			var segB:Segment = new Segment();
			
			var element:Document = new Document();
			element.tags = new Vector.<Segment>();
			element.tags.push(segA, segB);
			
			// setup action
			action = new AccessCellAction();
			action.tags = new Vector.<Segment>();
			
			context.activeTags = new Vector.<Segment>();
			context.activeTags.push(segB, segA);
			
			// execute action
			handler.execute(context, action);
			
			// assertions
			Assert.assertEquals(0, context.activeTags.length);
			Assert.assertTrue(context.invalidActiveTags);
		}
	}
}